<?php
/* MyMeeting is an online meeting management software.
 * Copyright (C) 2009 Government Of Malaysia
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * @author: Abdullah Zainul Abidin, Nuhaa All Bakry
 *          Eavay Javay Barnad, Sarogini Muniyandi, Teow Jit Huan
 *
 */

class Item extends AppModel {

/**
 * Defining the name of model
 *
 */
    var $name = 'Item';
/**
 * Defining the name of the table
 *
 */
    var $useTable = 'items';
/**
 * Displaying item short name
 *
 */
    var $displayField = 'name';
/**
 * Defining behavior in the model
 *
 */
    //var $actsAs = 'SoftDeletable';

    //validation
    var $committee_id = null;
/**
 * Validating the fields in group model
 *
 */
    var $validate = array(
        'name' => array(
            'required'=>array(
                'rule' => 'notEmpty'
            )
        )
    );   

    //The Associations below have been created with all possible keys, those that are not needed can be removed
/**
 * Building assosiations betweeen models
 *
 */
    var $belongsTo = array(
        'Committee' => array('className' => 'Committee',
        'foreignKey' => 'committee_id',
        'conditions' => '',
        'fields' => '',
        'order' => '')
    );

/**
 * Building assosiations betweeen models
 *
 */
    var $hasMany = array(
        'Decision' => array('className' => 'Decision',
        'foreignKey' => 'item_id',
        'dependent' => false,
        'conditions' => '',
        'fields' => '',
        'order' => '',
        'limit' => '',
        'offset' => '',
        'exclusive' => '',
        'finderQuery' => '',
        'counterQuery' => '')
    );
    
      /*
     * For validation
     * */
    function uniqueitem($value, $params=array()) {
        if($this->id==null){
            $item = $this->find('count',array('conditions'=>array('committee_id'=>$this->committee_id,'Item.short_name'=>$value)));
        }else{
            $item = $this->find('count',array('conditions'=>array('committee_id'=>$this->committee_id,'Item.short_name'=>$value,'not'=>array('Item.id'=>$this->id))));
        }
        if ($item) return false;
        else return true;
    }

}
?>
